package com.cloud.cluster.web;

import com.cloud.cluster.entity.Resume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.IntStream;

@RestController
@RequestMapping("/resume")
public class ResumeController {
    @Autowired
    private MongoTemplate mongoTemplate;

    @RequestMapping("/batch")
    public Object batch() {
        //return this.mongoTemplate.remove(new Query(), Resume.class);
        List<Resume> datas = new ArrayList<>();
        IntStream.range(0, 100).forEach(index -> {
            Resume r = new Resume();
            r.setName("架构师" + index);
            r.setExpectSalary((double) new Random().nextInt(20000) %(20000-10000+1) + 10000);
            r.setCity("广州");
            r.setBirthday(LocalDate.of(1995, 1, 1));
            datas.add(r);
        });
        return this.mongoTemplate.insertAll(datas);
    }
}

